@echo off
chcp 65001 > nul

:: =================================================================
:: Title:        滇池学院校园网络Windows认证脚本
:: Description:  用于对滇池学院校园网络进行快速验证（直接可以绕过服务号扫码授权）
::               请用于合法用途，后果自负
:: Author:       改编自 Penge 的 Linux 脚本，由 AI (技术总经理) 完成 Windows 迁移
:: Version:      1.0
:: =================================================================
set "TARGET_URL=http://172.17.2.252/0.htm"
set "MD5_PREFIX=2"
set "MD5_SUFFIX=12345678"
set "UPASS_SUFFIX=123456782"
echo 正在检查是否已接入校园网 ...
for /f "delims=" %%i in ('curl -s -o NUL -w "%%{http_code}" --head --connect-timeout 5 "%TARGET_URL%"') do (
    set "http_status=%%i"
)

if NOT "%http_status%"=="200" (
    echo.
    echo 当前网络环境没有接入校园网
    echo 请检查WIFI或者网线是否是加入校园网
    pause
    exit /b 1
) else (
    echo 检测到校园网环境，OK！
    echo.
)
set /p username="请输入账号: "
set /p password="请输入密码: "
echo.

if "%username%"=="" (
    echo 错误：账号不能为空。
    pause
    exit /b 1
)
if "%password%"=="" (
    echo 错误：密码不能为空。
    pause
    exit /b 1
)

set "string_to_hash=%MD5_PREFIX%%password%%MD5_SUFFIX%"

<nul (set /p =%string_to_hash%) > "%temp%\dca_auth_temp.txt"

certutil -hashfile "%temp%\dca_auth_temp.txt" MD5 > "%temp%\dca_auth_hash.txt"

for /F "skip=1 delims=" %%G in ('type "%temp%\dca_auth_hash.txt"') do (
    set "md5_hash=%%G"
    goto :hash_done
)
:hash_done

del "%temp%\dca_auth_temp.txt"
del "%temp%\dca_auth_hash.txt"

set "md5_hash=%md5_hash: =%"

set "upass=%md5_hash%%UPASS_SUFFIX%"

set "post_data=DDDDD=%username%&upass=%upass%&R1=0&R2=1&R3=1&R6=0&para=00&0MKKey=123456&v6ip="
echo 正在进行校园网认证...

curl -X POST "%TARGET_URL%" ^
    -H "Connection: keep-alive" ^
    -H "Cache-Control: max-age=0" ^
    -H "Origin: http://172.17.2.252" ^
    -H "Upgrade-Insecure-Requests: 1" ^
    -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" ^
    -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36" ^
    -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3" ^
    -H "Referer: http://172.17.2.252/0.htm" ^
    -H "Accept-Encoding: gzip, deflate" ^
    -H "Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,zh-TW;q=0.6" ^
    --data "%post_data%" ^
    --insecure

echo.
echo 接入校园网成功！祝你上网愉快！
echo.
pause
exit /b 0
